package Java.BlackHorse.Exception;

public class ExceptionDemo2 {
    public static void main(String[] args) {
        int[] arr = null;
        int max = 0;
        try {
            max = getMax(arr);
        } catch (NullPointerException e) {
            System.out.println("空指针异常");
        }catch(ArrayIndexOutOfBoundsException e){
            System.out.println("数组越界异常");
        }

        System.out.println(max);
    }

    public static int getMax(int[] arr){
        if(arr == null){
            throw new NullPointerException();
        }

        if(arr.length == 0){
            throw new ArrayIndexOutOfBoundsException();
        }

        int max=arr[0];
        for(int i = 1;i<arr.length;i++){
            if(max < arr[i]) max=arr[i];
        }
        return max;
    }

}
